package com.gestocasa.model;

import java.util.UUID;
import java.util.Vector;

public class Configuration implements Comparable<Configuration> {

	private int id;
	private UUID internalId;
	private String name;
	private int order;
	private Vector<Descriptor> descriptors;
		
	public Configuration() {
		this(null);
	}

	public Configuration(Configuration c) {
		descriptors = new Vector<Descriptor>();
		if(c == null) {
			id = -1;
			internalId = UUID.randomUUID();
			name = "";
			order = 0;
		}
		else {
			id = c.getId();
			internalId = c.getInternalId();
			name = c.getName();
			order = c.getOrder();
			
			if(c.getDescriptors() != null) {
				for(Descriptor d : c.getDescriptors()) {
					descriptors.add(new Descriptor(d));
				}
			}
		}
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public UUID getInternalId() {
		return internalId;
	}

	public void setInternalId(String internalId) {
		setInternalId((internalId == null) ? UUID.randomUUID() : UUID.fromString(internalId));
	}
	
	public void setInternalId(UUID internalId) {
		this.internalId = internalId;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getOrder() {
		return order;
	}

	public void setOrder(int order) {
		this.order = order;
	}

	public Vector<Descriptor> getDescriptors() {
		return descriptors;
	}

	public void setDescriptors(Vector<Descriptor> descriptors) {
		this.descriptors = descriptors;
	}

	public boolean equals(Configuration configuration) {
		return (configuration == null) ? false : internalId.equals(configuration.getInternalId());
	}
	
	@Override
	public int compareTo(Configuration o) {
		if(order == o.getOrder()) {
			if(name == null || o.getName() == null) {
				return 0;
			}
			else {
				return name.compareTo(o.getName());
			}
		}
		else {
			if(order < o.getOrder()) {
				return -1;
			}
			else if(order > o.getOrder()) {
				return 1;
			}
			else {
				return 0;
			}
		}
	}
}
